<?php
require_once('../lib/standard.php');
require_once('../lib/notes.php');
set_pineza(TRUE);
$pineza->fetch_user();
$board = (perastike('board') ? $_REQUEST['board'] : '');
$search = (perastike('search') ? $_REQUEST['search'] : FALSE);
if (perastike('neo')) {
	if (perastike('note'))
		enimerosi_simioma($_REQUEST['note'], $board);
	else
		neo_simioma($board);
}
?>
<link rel="stylesheet" type="text/css" href="<?php print $pineza->server; ?>board/boardIcon.css" />
<script type="text/javascript" src="<?php print $pineza->server; ?>board/board.js"></script>
</head>
<body style="<?php
	if (perastike('search')) {
		?>
		background-image: url('<?php
			print $pineza->server; ?>images/kare.gif'); background-repeat: repeat;
		<?php
	}
	elseif ($board) {
		?>
		background-image: url('<?php print $pineza->server; ?>images/tsoxes/<?php
			print $board; ?>.jpg'); background-repeat: repeat;
		<?php
	}
?>cursor: pointer;" title="Double click for new post"
	ondblclick="return(neoSimioma(parent));">
<img src="<?php print $pineza->server; ?>images/working.gif"
	style="display: none;" alt="preload image" />
<div id="debug" class="debug">Debug area</div>
<div id="formaNotePosition"></div>
<?php
if (perastike('search')) {
	search_notes($search);
}
else {
	?>
	<div id="boardNotes">
		<?php print_board($pineza->login, $board); ?>
	</div>
	<?php
}
?>
<script type="text/javascript">
pineza.board = '<?php print $board; ?>';
pineza.search = '<?php print $search; ?>';
pineza.myEmail = '<?php print $pineza->user->email; ?>';
<?php
if ((!perastike('epilogi')) && perastike('neo')) {
	?>
	refreshBoardSB('<?php print $board; ?>');
	<?php
}
?>
</script>
</body>
</html>
<?php

function search_notes($pat) {
	global $pineza;
	set_pineza();
	$query = "SELECT * FROM `note` WHERE `user` = '" .
		escape($pineza->login) .  "' AND `text` LIKE '%" .
		escape($pat) .  "%' ORDER BY `priority` DESC, `key` DESC";
	$result = mysqli_query($pineza->db, $query);
	if (!$result)
		telos(mysqli_error($pineza->db));

	while ($note = mysqli_fetch_array($result, MYSQLI_ASSOC))
		print_note($note);
}

function neo_simioma($board) {
	global $pineza;
	if (!$pineza->login)
		return;

	if ((!perastike('localTime')) || (!$_REQUEST['localTime'])) telos('no local time passed');
	else $date = $_REQUEST['localTime'];

	if (!perastike('kimeno')) return;
	else $kimeno = proc_kimeno($_REQUEST['kimeno']);

	if (!perastike('font')) $font = NULL;
	else $font = $_REQUEST['font'];

	if (!perastike('color')) $color = NULL;
	else $color = $_REQUEST['color'];

	new_note($pineza->login, $board, $kimeno, $font, $color, $date);
}

function enimerosi_simioma($note, $board) {
	global $pineza;
	if (!$pineza->login)
		return;

	if (!perastike('kimeno')) return;
	else $kimeno = proc_kimeno($_REQUEST['kimeno']);

	if (!perastike('font')) $font = NULL;
	else $font = $_REQUEST['font'];

	if (!perastike('color')) $color = NULL;
	else $color = $_REQUEST['color'];
	$query = "UPDATE `note` SET `board` = '" . escape($board) . "', " .
		"`text` = '" . escape($kimeno) . "', " .
		"`color` = '" . escape($color) . "', " .
		"`font` = '" . escape($font) . "' " .
		"WHERE `key` = " . escape($note);
	mysqli_query($pineza->db, $query);
}

function proc_kimeno($s) {
	return($s);
}
?>
